ECHO=echo
BUILD_DIR=../../build/bz

LD=ld
LD_FLAGS=-T linker.ld
OBJCOPY=objcopy
OC_FLAGS=--remove-section .comment

DIRS=bootstrap mm kernel 

build: kernel
all: clean kernel

kernel: compile
	@$(ECHO) "** Linking"
	@$(ECHO) $(LD) $(LD_FLAGS) -o $(BUILD_DIR)/$@.bz $(BUILD_DIR)/*.ko
	@$(LD) $(LD_FLAGS) -o $(BUILD_DIR)/$@.bz $(BUILD_DIR)/*.ko
	@$(OBJCOPY) $(OC_FLAGS) $(BUILD_DIR)/$@.bz

compile: 
	@mkdir -p ../../build/bz
	@$(ECHO) "** Compiling"
	@for dir in $(DIRS); do $(ECHO) + $$dir; make -C $$dir; done

clean:
	@$(ECHO) "** Cleaning"
	@$(ECHO) "rm -rf $(BUILD_DIR)/*.ko; rm -rf $(BUILD_DIR)/*.bz"
	@rm -rf $(BUILD_DIR)/*.ko; rm -rf $(BUILD_DIR)/*.bz
	@for dir in $(DIRS); do $(ECHO) + $$dir; make -C $$dir clean; done
